package com.happy.study.servier.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.happy.study.dao.NoteMapper;
import com.happy.study.entity.NoteEntity;
import com.happy.study.servier.INoteService;
import com.happy.study.util.StateEnum;
import com.happy.study.util.StateException;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Wuzh
 * @Description:
 * @Date Created in 21:48 2021/1/27
 * @return
 */

@Service
public class NoteServiceImpl extends ServiceImpl<NoteMapper, NoteEntity> implements INoteService {


    @Resource
    private NoteMapper noteMapper;


    @Override
    public List<NoteEntity> queryList ( NoteEntity noteEntity ) {
        if ( noteEntity == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        List<NoteEntity> noteEntities = noteMapper.queryList ( noteEntity.getCategoryId (), ( noteEntity.getPageNum () - 1 ) * noteEntity.getPageSize (), noteEntity.getPageSize () );
        return noteEntities;
    }

    @Override
    public int queryCount ( NoteEntity noteEntity ) {
        int count = noteMapper.queryCount ( noteEntity.getCategoryId () );
        return count;
    }

    @Override
    public NoteEntity querySingle ( int id ) {
        if ( id == 0 ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        NoteEntity noteEntity = baseMapper.selectById ( id );
        return noteEntity;
    }
}
